package com.naicha.wechat.wechat.face;

/**
 * @author NaiCha
 * @date 2019/5/9 16:34
 * @description TODO
 **/
/**
 * @Description TODO
 * @author 奶茶
 * Created by on 2018/12/13 14:11.
 */
public abstract class AbstractPrime {

    /**
     * 判断一个数是否为素数
     * @param number
     * @return
     */
    private boolean isPrime(int number){
        if(number <= 1) return false;
        for (int i=2;i<=Math.sqrt(number);i++){
            if (number%i == 0) return false;
        }
        return true;
    }

    /**
     * 判断某一范围内质数的个数
     * @param start
     * @param end
     * @return
     */
    public Integer countPrimeInRange(Integer start, Integer end){
        Integer count= 0;
        for (int i=start;i<=end;i++){
            if (isPrime(i)){
                count++;
            }
        }
        return count;
    }

    /**
     * 统计素数
     * @param number
     * @return
     */
    public abstract Integer countPrime(Integer number);

}
